package com.aiclient.service;

import javafx.scene.Scene;
import javafx.scene.input.KeyCombination;
import java.util.HashMap;
import java.util.Map;

public class ShortcutService {
    private final Map<KeyCombination, Runnable> shortcuts = new HashMap<>();
    private Scene scene;

    public void setScene(Scene scene) {
        this.scene = scene;
        registerShortcuts();
    }

    public void addShortcut(KeyCombination combination, Runnable action) {
        shortcuts.put(combination, action);
        if (scene != null) {
            scene.getAccelerators().put(combination, action);
        }
    }

    public void registerShortcuts() {
        if (scene == null) return;
        
        // 清除现有快捷键
        scene.getAccelerators().clear();
        
        // 重新注册所有快捷键
        shortcuts.forEach((combination, action) -> 
            scene.getAccelerators().put(combination, action)
        );
    }
} 